package com.qch.rabbitmq.demo;

import com.rabbitmq.client.*;

import java.io.IOException;

/**
 * @Author qch
 * @Date 2021/5/13
 */
public class WarnConsumer {
    public static void main(String[] args)throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setUri("amqp://root:123456@192.168.142.135:5672/%2f");
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare("ex.routing","direct",false,false,null);

        channel.queueDeclare("queue.warn",false,false,false,null);
       channel.queueBind("queue.warn","ex.routing","WARN");
        channel.basicConsume("queue.warn", new DeliverCallback() {
            public void handle(String consumerTag, Delivery message) throws IOException {
                System.out.println("WarnConsumer收到的消息"+new String(message.getBody(),"utf-8"));
            }
        }, new CancelCallback() {
            public void handle(String consumerTag) throws IOException {
                System.out.println("Cancel"+consumerTag);
            }
        });
    }
}
